//
//  SlideViewController.swift
//  DemoProject
//
//  Created by hao on 2018/7/18.
//  Copyright © 2018年 hao. All rights reserved.
//

import UIKit

class SlideViewController: BaseTableViewController {

    let disposeBag = DisposeBag()
    
    lazy var slider: UISlider = {
        let _slider = UISlider()
        self.tableHeadView.addSubview(_slider)
        _slider.snp.makeConstraints({ (make) in
            make.center.equalTo(self.tableHeadView)
            make.width.equalTo(200)
            make.height.equalTo(44)
        })
        return _slider
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // 禁止手势pop回上一级
        self.fd_interactivePopDisabled = true
        // 同理 MinimumTrackImage表示滑过的样式，MaximumTrackImage相当于背景的图片
//        slider.setMaximumTrackImage(UIImage(named:"slider_track_image"),for: .normal)
//        slider.setMinimumTrackImage(UIImage(named:"slider_track_image"), for: .normal)
        // 红色就充当了滑块所滑过的颜色
        slider.minimumTrackTintColor = UIColor.red
        // 绿色表示了该滑块的背景颜色
        slider.maximumTrackTintColor = UIColor.green
        // 设置滑块的图片(即拖拽的圆)
        slider.setThumbImage(UIImage(named:"slider_thumb_image"), for: .normal)
        // 设置滑块右边部分的图片
        slider.maximumValueImage = UIImage(named: "btn_next_play")
        // 设置滑块左边部分的图片
        slider.minimumValueImage = UIImage(named: "btn_last_play")
        setupData()
        _rxSwiftProperty()
    }
    
    private func _rxSwiftProperty() {
        slider.rx.value.asObservable().subscribe(onNext: { print(info: "当前值为: \($0)") }).disposed(by: disposeBag)
    }
    
    private func setupData() {
        let titles = ["minimumValue",
                      "maximumValue",
                      "continuous",
                      "minimumValueImage",
                      "maximumValueImage",
                      "minimumTrackTintColor",
                      "maximumTrackTintColor",
                      "thumbTintColor",
                      "自定义滑块组件图片",
                      "currentMaximumTrackImage",
                      "currentMinimumTrackImage",
                      "currentThumbImage"]
        
        let descArr = ["当值可以改变时，滑块可以滑动到最小位置的值，默认为0.0",
                       "当值可以改变时，滑块可以滑动到最大位置的值，默认为1.0",
                       """
                        如果设置YES，在拖动滑块的任何时候，滑块的值都会改变。默认设置为YES
                        [slider setContinuous:NO]; // 在滑块滑动结束时才获取滑块的值
                       """,
                       """
                        滑块条最小值处设置的图片，默认为nil
                        slider.minimumValueImage = [UIImage imageNamed:@"btn_last_play"];
                       """,
                       """
                        滑块条最大值处设置的图片,默认为nil
                        slider.maximumValueImage  = [UIImage imageNamed:@"btn_next_play"];
                       """,
                       """
                        小于滑块当前值滑块条的颜色，默认为蓝色
                        slider.minimumTrackTintColor = [UIColor redColor];
                       """,
                       """
                        大于滑块当前值滑块条的颜色，默认为白色
                        slider.maximumTrackTintColor = [UIColor greenColor];
                       """,
                       """
                        当前滑块的颜色，默认为白色
                        slider.thumbTintColor = [UIColor yellowColor];
                       """,
                       """
                        slider.setMaximumTrackImage(UIImage(named:"slider_max"),for: .normal)
                        slider.setMinimumTrackImage(UIImage(named:"slider_min"),for: .normal)
                        // 设置滑块的图片
                        slider.setThumbImage(UIImage(named:"slider_thumb"),for: .normal)

                        // 设置滑块右边部分的图片-使用三宫格缩放（左右14像素不变，中间缩放）
                        let imgTrackRight = UIImage(named:"slider_max")
                        let imgRight = imgTrackRight!.stretchableImage(withLeftCapWidth: 14, topCapHeight:0)
                        slider.setMaximumTrackImage(imgRight, for: .normal)
                       """,
                       "滑块条最大值处设置的图片",
                       "滑块条最小值处设置的图片",
                       "当前滑块的图片"]
        
        addTitles(titles, footDescs: descArr)
    }

}
